package project1;

import java.applet.Applet;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Polygon;
import java.awt.Toolkit;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class Applet2
  extends Applet
  implements MouseListener, MouseMotionListener
{
  boolean etatCarre = false;
  boolean etatCarre2 = false;
  int x=-1;
  int y=-1;
  public Applet2()
  {
   
  }

  private void jbInit()
    throws Exception
  {
    this.setLayout( null );
  }
 /* public void paint(Graphics g)
  {
    
   if (etatCarre)
   { g.setColor(Color.PINK);
    g.drawRect(200,200,100,100);
   }
   else
   {
     g.setColor(Color.YELLOW);
    g.drawRect(200,200,100,100);
   }
   
    if (etatCarre2)
    { g.setColor(Color.PINK);
      g.drawRect(300,300,100,100);
    }
    else
    {
      g.setColor(Color.YELLOW);
      g.drawRect(300,300,100,100);
    }
  

    
  }*/
  
  public void paint(Graphics g)
  {
    g.fillOval(x,y,50,50);
  }
  public void init()
  {
    this.addMouseListener(this);
    this.addMouseMotionListener(this);
    try
    {
      jbInit();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
  }

  public static void main(String[] args)
  {
    Applet2 applet = new Applet2();
    Frame frame = new Frame();
    frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } } );
    frame.add(applet, BorderLayout.CENTER);
    frame.setTitle( "Carres" );
    applet.init();
    applet.start();
    frame.setSize(800, 600);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = frame.getSize();
    frame.setLocation((d.width-frameSize.width)/2, (d.height-frameSize.height)/2);
    frame.setVisible(true);
  }

  public void start()
  {
  }

  public void stop()
  {
  }

  public void destroy()
  {
  }

  public void mouseClicked(MouseEvent e)
  {
   /* if (e.getX()<300 && e.getX()>200 && e.getY()>200 && e.getY()<300 )
      etatCarre = !etatCarre;
    else if (e.getX()<400 && e.getX()>300 && e.getY()>300 && e.getY()<400 )
      etatCarre2= !etatCarre2; */
    repaint();
  }

  public void mousePressed(MouseEvent e)
  {
  }

  public void mouseReleased(MouseEvent e)
  {
    
  }

  public void mouseEntered(MouseEvent e)
  {
  }

  public void mouseExited(MouseEvent e)
  {
  }

  public void mouseDragged(MouseEvent e)
  {
    x= e.getX();
    y= e.getY();
    paint(getGraphics());
  }

  public void mouseMoved(MouseEvent e)
  {

  }
}
